﻿@model List<CMSMVC4.CateLang>
<script language="javascript" type="text/javascript">
    $(function () {
        $("#sortable").sortable();
        $("#sortable").disableSelection();
        $("#paren").change(function () {
            var url = "/Admin/Services/Sort/" + $(this).val();
            window.location.href = url;
        });
    });

    function save() {
        var aro = [];
        $('#sortable .ui-state-default').each(function (i) {
            var id = $('.ui-state-default').eq(i).attr('index');
            var sort = $('.ui-state-default').eq(i).attr('sort'); ;
            var ob = { "id": id, "sort": sort };
            ob.id = id;
            ob.sort = sort;
            aro.push(ob);
        });
        for (var i = 0; i < aro.length - 1; i++) {
            for (var j = i; j < aro.length; j++) {
                if (aro[i].sort < aro[j].sort) {
                    var t = aro[i].sort;
                    aro[i].sort = aro[j].sort;
                    aro[j].sort = t;
                }
            }
        }
        $.ajax({
            type: "Post",
            dataType: "json",
            contentType: 'application/json; charset=utf-8',
            url: "/Admin/ThietBi/Sort",
            data: JSON.stringify(aro),
            success: function (data) {
                $('#eMessage').html(data);
                $('#eMessage').fadeIn();
                $('#eMessage').fadeOut(5000);
            }
        });
    }
</script>
<div class="row-fluid">
    <div class=" span6" style="width: 100%;">
        @if (Model != null)
        {
            <div class="box paint color_7">
                <div class="title">
                    <div class="row-fluid">
                        <h4>
                            Sắp Xếp Dịch Vụ
                        </h4>
                    </div>
                </div>
                <!-- End .title -->
                <div class="content">
                    <div id="gmap1" style="height: 300px; width: 100%">
                        <div id="eMessage">
                        </div>
                        <div class="form-row control-group row-fluid">
                        <label class="control-label span3">Chọn danh mục <span class="help-block">Chọn danh mục</span>
                        </label>
                        <div class="controls span7">
                            @{ Html.RenderAction("DanhSachDanhMuc", "Services", new {id = ViewBag.id}); }
                        </div>
                    </div>
                        <ul id="sortable">
                            @foreach (var i in Model)
                            {
                                <li class="ui-state-default" index = "@i.CategoriesId" sort = "@i.Category.Sort"><span
                                    class="ui-icon ui-icon-arrowthick-2-n-s"></span>@i.Name</li>
                            }
                            <br/>
                            <button type="button" onclick="save()" class="btn btn-primary">Save changes</button>
                        </ul>
                    </div>
                </div>
            </div>
        }
    </div>
</div>
